﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.ReflectionModel;
using System.Linq;
using System.Reflection;
using Microsoft.Internal;

namespace System.ComponentModel.Composition.Caching.AttributedModel
{
    internal class CachedAttributedComposablePart : ReflectionComposablePart
    {
        private readonly CachedAttributedComposablePartDefinition _definition;

        public CachedAttributedComposablePart(CachedAttributedComposablePartDefinition definition)
        {
            Assumes.NotNull(definition);

            _definition = definition;
        }

        public override ReflectionComposablePartDefinition Definition
        {
            get { return _definition; }
        }

        protected override ImportingItem GetImportingItem(ImportDefinition definition)
        {
            CachedAttributedImportDefinition attributedDefinition = definition as CachedAttributedImportDefinition;
            if (attributedDefinition != null)
            {
                return attributedDefinition.ToImportingItem(() => _definition.Constructor);
            }

            // Don't recognize it
            return null;
        }

        protected override ExportingMember GetExportingMember(ExportDefinition definition)
        {
            CachedAttributedExportDefinition attributedDefinition = definition as CachedAttributedExportDefinition;
            if (attributedDefinition != null)
            {
                return attributedDefinition.ToExportingMember();
            }

            // Don't recognize it
            return null;
        }
    }
}
